/*
 * @Author: 噜噜雯雯 2199987619@qq.com
 * @Date: 2025-05-27 08:43:07
 * @LastEditors: 噜噜雯雯 2199987619@qq.com
 * @LastEditTime: 2025-07-11 15:46:51
 * @FilePath: \linePatrol\vue-element-plus-admin\src\api\role\index.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import service from '@/axios/http'
import { TableIResponse } from '@/utils/Api'
import { ParamType, RoleListType, MenuTreeType } from './type'

export class RoleApi {
  async GetRoleList(params: ParamType): Promise<TableIResponse<RoleListType[]>> {
    const result = (await service.get('/api/system/role/list', { params })) as unknown as any
    return result
  }
  async GetMenuTree(): Promise<MenuTreeType[]> {
    const result = (await service.get('/api/system/menu/treeselect')) as unknown as any
    const { code, data } = result
    if (code == 200) {
      return data
    } else {
      return []
    }
  }
  // async GetMenuTree(): Promise<MenuTreeType[]> {
  //   const result = await service.get('/api/system/menu/treeselect') as unknown as any;
  //   const {code,data}=result;
  //   if(code==200){
  //     return data
  //   }else{
  //     return []
  //   }
  // }
  //删除角色
  async DeletRole(roleIds: number): Promise<boolean> {
    const result = (await service.delete(`/api/system/role/${roleIds}`)) as unknown as any
    const { code } = result as any
    if (code == 200) {
      return true
    } else {
      return false
    }
  }
  //新增角色
  async AddRole(data: RoleListType): Promise<boolean> {
    const result = (await service.post('/api/system/role', data)) as unknown as any
    const { code } = result as any
    if (code == 200) {
      return true
    } else {
      return false
    }
  }
  //修改角色
  async EditRole(data: RoleListType): Promise<boolean> {
    const result = (await service.put('/api/system/role', data)) as unknown as any
    const { code } = result as any
    if (code == 200) {
      return true
    } else {
      return false
    }
  }
  // 查询角色菜单绑定数据
  async GetRoleMenuTree(roleId: number | undefined): Promise<any> {
    const result = (await service.get(
      `/api/system/menu/roleMenuTreeselect/${roleId}`
    )) as unknown as any
    const { code } = result
    if (code == 200) {
      return result
    } else {
      return null
    }
  }
  //修改权限
  async EditDataScope(data: RoleListType): Promise<boolean> {
    const result = (await service.put('/api/system/role/dataScope', data)) as unknown as any
    const { code } = result as any
    if (code == 200) {
      return true
    } else {
      return false
    }
  }
  // 角色已授权用户
  async GetAuthUser(params): Promise<any> {
    const result = (await service.get(`/api/system/role/authUser/allocatedList`, {
      params
    })) as unknown as any
    const { code } = result
    if (code == 200) {
      return result
    } else {
      return null
    }
  }
  // 查询未分配用户角色列表
  async UnallocatedUser(params): Promise<any> {
    const result = (await service.get(`/api/system/role/authUser/unallocatedList`, {
      params
    })) as unknown as any
    const { code } = result
    if (code == 200) {
      return result
    } else {
      return null
    }
  }
  // 取消角色授权用户
  async CancelAuthUser(data): Promise<any> {
    const result = (await service.put(`/api/system/role/authUser/cancel`, data)) as unknown as any
    const { code } = result as any
    if (code == 200) {
      return true
    } else {
      return false
    }
  }
  // 角色添加用户
  async EditAuthUser(data: any): Promise<boolean> {
    const result = (await service.put(
      '/api/system/role/authUser/selectStrAll',
      data
    )) as unknown as any
    const { code } = result as any
    if (code == 200) {
      return true
    } else {
      return false
    }
  }
  //批量取消授权
  async BatchCancelAuthUser(data: { roleId: any; userIds: any }): Promise<boolean> {
    const result = (await service.put(
      '/api/system/role/authUser/cancelStrAll',
      data
    )) as unknown as any
    const { code } = result as any
    if (code == 200) {
      return true
    } else {
      return false
    }
  }
}
export default new RoleApi()
